<UserControl x:Class="BookDemoApp.UCCube"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:BookDemoApp">
  <UserControl.Triggers>
    <EventTrigger RoutedEvent="UserControl.Loaded" >
      <EventTrigger.Actions>
        <BeginStoryboard>
          <Storyboard>
            <ParallelTimeline RepeatBehavior="Forever"  Storyboard.TargetName="myRotate" Storyboard.TargetProperty="Angle" >
              <DoubleAnimation From="0" To="360" Duration="0:0:30" RepeatBehavior="Forever"/>
            </ParallelTimeline>
            <ParallelTimeline RepeatBehavior="Forever"  Storyboard.TargetName="myRotate2" Storyboard.TargetProperty="Angle" >
              <DoubleAnimation From="0" To="360" Duration="0:0:30" RepeatBehavior="Forever"/>
            </ParallelTimeline>
            <ParallelTimeline RepeatBehavior="Forever"  Storyboard.TargetName="myScale" Storyboard.TargetProperty="ScaleX" >
              <DoubleAnimation From="0.5" To="1.5" Duration="0:0:10" AutoReverse="True" RepeatBehavior="Forever"/>
            </ParallelTimeline>
            <ParallelTimeline RepeatBehavior="Forever"  Storyboard.TargetName="myScale" Storyboard.TargetProperty="ScaleY" >
              <DoubleAnimation From="0.5" To="1.5" Duration="0:0:10" AutoReverse="True" RepeatBehavior="Forever"/>
            </ParallelTimeline>
            <ParallelTimeline RepeatBehavior="Forever"  Storyboard.TargetName="myScale" Storyboard.TargetProperty="ScaleZ" >
              <DoubleAnimation From="0.5" To="1.5" Duration="0:0:10" AutoReverse="True" RepeatBehavior="Forever"/>
            </ParallelTimeline>
          </Storyboard>
        </BeginStoryboard>
      </EventTrigger.Actions>
    </EventTrigger>
  </UserControl.Triggers>
  <UserControl.Resources>
    <Storyboard x:Key="RotateStoryboard">
      <ParallelTimeline RepeatBehavior="Forever"  Storyboard.TargetName="myRotate" Storyboard.TargetProperty="Angle" >
        <DoubleAnimation From="0" To="360" Duration="0:0:30"/>
      </ParallelTimeline>
    </Storyboard>

    <MeshGeometry3D x:Key="PlaneMesh"
            Positions="-1 -1 0  1 -1 0  -1 1 0  1 1 0"
            Normals="0 0 1  0 0 1  0 0 1  0 0 1"
            TextureCoordinates="0 1  1 1  0 0  1 0   "
            TriangleIndices="0 1 2  1 3 2" />

    <MeshGeometry3D x:Key="CubeMesh"
      TriangleIndices="0,1,2 3,4,5 6,7,8 9,10,11 12,13,14 15,16,17 18,19,20 21,22,23 24,25,26 27,28,29 30,31,32 33,34,35 "
      Normals="0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,-1,0 0,-1,0 0,-1,0 0,-1,0 0,-1,0 0,-1,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 0,1,0 0,1,0 0,1,0 0,1,0 0,1,0 0,1,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 "
      TextureCoordinates="1,0 1,1 0,1 0,1 0,0 1,0 0,0 1,0 1,1 1,1 0,1 0,0 0,0 1,0 1,1 1,1 0,1 0,0 1,0 1,1 0,1 0,1 0,0 1,0 1,1 0,1 0,0 0,0 1,0 1,1 0,1 0,0 1,0 1,0 1,1 0,1 "
      Positions="-0.5,-0.5,-0.5 -0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,-0.5,-0.5 -0.5,-0.5,-0.5 -0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,-0.5,0.5 0.5,-0.5,0.5 -0.5,-0.5,0.5 -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,0.5 0.5,0.5,0.5 0.5,-0.5,0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5 -0.5,0.5,-0.5 -0.5,0.5,0.5 -0.5,0.5,0.5 0.5,0.5,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.5,-0.5,0.5 -0.5,-0.5,-0.5 -0.5,0.5,-0.5 -0.5,0.5,-0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 "
		/>

    <Transform3DGroup x:Key="CubeMeshTransform">
      <Transform3DGroup.Children>
        <ScaleTransform3D ScaleX="10" ScaleY="10" ScaleZ="10" />
      </Transform3DGroup.Children>
    </Transform3DGroup>

    <Transform3DGroup x:Key="CubeMeshTransform2">
      <Transform3DGroup.Children>
        <ScaleTransform3D ScaleX="12" ScaleY="12" ScaleZ="12" />
      </Transform3DGroup.Children>
    </Transform3DGroup>
  </UserControl.Resources>

  <DockPanel>
    <DockPanel.Background>
      <LinearGradientBrush StartPoint="0 0" EndPoint="0 1">
        <GradientStop Color="Purple" Offset="0" />
        <GradientStop Color="Bisque" Offset="1" />
      </LinearGradientBrush>
    </DockPanel.Background>
    <TextBlock Text="WPF Flip page sample" Foreground="White"
           FontSize="16" HorizontalAlignment="Center"
           Margin="10" DockPanel.Dock="Top"/>
    <DockPanel>
      <local:UCTitle DockPanel.Dock="Bottom" DataContext="Hardware accelerated 3D" />
      <Viewport3D Focusable="True" Name="myViewport3D" ClipToBounds="True" >
        <Viewport3D.Camera>
          <PerspectiveCamera
          Position="0,0,3.0"
          LookDirection="0,0,-1"
          UpDirection="0,1,0"
          NearPlaneDistance="0.25"
          FarPlaneDistance="20"
          FieldOfView="60" />
        </Viewport3D.Camera>

        <ModelVisual3D>
          <ModelVisual3D.Transform>
            <Transform3DGroup>
              <Transform3DGroup.Children>
                <Transform3DCollection >
                  <ScaleTransform3D ScaleX="1" ScaleY="1"  ScaleZ="1" />
                  <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                      <AxisAngleRotation3D Axis="0 1 0" Angle="0" />
                    </RotateTransform3D.Rotation>
                  </RotateTransform3D>
                  <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0" />
                </Transform3DCollection>
              </Transform3DGroup.Children>
            </Transform3DGroup>
          </ModelVisual3D.Transform>
          <ModelVisual3D.Content>
            <Model3DGroup >
              <Model3DGroup.Transform>
                <Transform3DGroup>
                  <Transform3DGroup.Children>
                    <Transform3DCollection >
                      <ScaleTransform3D ScaleX="0.1" ScaleY="0.1"  ScaleZ="0.1" />
                      <RotateTransform3D>
                        <RotateTransform3D.Rotation>
                          <AxisAngleRotation3D Axis="0 1 0" Angle="0" />
                        </RotateTransform3D.Rotation>
                      </RotateTransform3D>
                      <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0" />
                    </Transform3DCollection>
                  </Transform3DGroup.Children>
                </Transform3DGroup>
              </Model3DGroup.Transform>
              <Model3DGroup.Children>

                <!--Group Child 0-->

                <Model3DGroup >
                  <Model3DGroup.Transform>
                    <Transform3DGroup>
                      <Transform3DGroup.Children>
                        <Transform3DCollection >
                          <ScaleTransform3D x:Name="myScale" ScaleX="0.5" ScaleY="0.5"  ScaleZ="0.5" />
                          <RotateTransform3D >
                            <RotateTransform3D.Rotation >
                              <AxisAngleRotation3D x:Name="myRotate" Axis="1 0 0" Angle="0" />
                            </RotateTransform3D.Rotation>
                          </RotateTransform3D>
                          <RotateTransform3D >
                            <RotateTransform3D.Rotation >
                              <AxisAngleRotation3D x:Name="myRotate2" Axis="0 1 0" Angle="0" />
                            </RotateTransform3D.Rotation>
                          </RotateTransform3D>
                          <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0" />
                        </Transform3DCollection>
                      </Transform3DGroup.Children>
                    </Transform3DGroup>
                  </Model3DGroup.Transform>

                  <Model3DGroup.Children>

                    <!--Child 0-->

                    <GeometryModel3D Transform="{StaticResource CubeMeshTransform}" Geometry="{StaticResource CubeMesh}" >
                      <GeometryModel3D.Material>
                        <MaterialGroup>
                          <MaterialGroup.Children>
                            <EmissiveMaterial>
                              <EmissiveMaterial.Brush>
                                <ImageBrush ImageSource="images\roundcornersheet.png">
                                  <ImageBrush.Transform>
                                    <TransformGroup>
                                      <TransformGroup.Children>
                                        <RotateTransform CenterX="0.5" CenterY="0.5" Angle="0" />
                                      </TransformGroup.Children>
                                    </TransformGroup>
                                  </ImageBrush.Transform>
                                </ImageBrush>
                              </EmissiveMaterial.Brush>
                            </EmissiveMaterial>
                          </MaterialGroup.Children>
                        </MaterialGroup>
                      </GeometryModel3D.Material>

                      <GeometryModel3D.BackMaterial>
                        <MaterialGroup>
                          <MaterialGroup.Children>
                            <EmissiveMaterial>
                              <EmissiveMaterial.Brush>
                                <ImageBrush ImageSource="images\roundcornersheet.png">
                                  <ImageBrush.Transform>
                                    <TransformGroup>
                                      <TransformGroup.Children>
                                        <RotateTransform CenterX="0.5" CenterY="0.5" Angle="0" />
                                      </TransformGroup.Children>
                                    </TransformGroup>
                                  </ImageBrush.Transform>
                                </ImageBrush>
                              </EmissiveMaterial.Brush>
                            </EmissiveMaterial>
                          </MaterialGroup.Children>
                        </MaterialGroup>
                      </GeometryModel3D.BackMaterial>
                    </GeometryModel3D>

                    <GeometryModel3D Transform="{StaticResource CubeMeshTransform2}" Geometry="{StaticResource CubeMesh}" >
                      <GeometryModel3D.Material>
                        <MaterialGroup>
                          <MaterialGroup.Children>
                            <EmissiveMaterial>
                              <EmissiveMaterial.Brush>
                                <ImageBrush ImageSource="images\roundcornersheet.png">
                                  <ImageBrush.Transform>
                                    <TransformGroup>
                                      <TransformGroup.Children>
                                        <RotateTransform CenterX="0.5" CenterY="0.5" Angle="0" />
                                      </TransformGroup.Children>
                                    </TransformGroup>
                                  </ImageBrush.Transform>
                                </ImageBrush>
                              </EmissiveMaterial.Brush>
                            </EmissiveMaterial>
                          </MaterialGroup.Children>
                        </MaterialGroup>
                      </GeometryModel3D.Material>

                      <GeometryModel3D.BackMaterial>
                        <MaterialGroup>
                          <MaterialGroup.Children>
                            <EmissiveMaterial>
                              <EmissiveMaterial.Brush>
                                <ImageBrush ImageSource="images\roundcornersheet.png">
                                  <ImageBrush.Transform>
                                    <TransformGroup>
                                      <TransformGroup.Children>
                                        <RotateTransform CenterX="0.5" CenterY="0.5" Angle="0" />
                                      </TransformGroup.Children>
                                    </TransformGroup>
                                  </ImageBrush.Transform>
                                </ImageBrush>
                              </EmissiveMaterial.Brush>
                            </EmissiveMaterial>
                          </MaterialGroup.Children>
                        </MaterialGroup>
                      </GeometryModel3D.BackMaterial>
                    </GeometryModel3D>
                  </Model3DGroup.Children>
                </Model3DGroup>
                <Model3DGroup>
                  <Model3DGroup.Children>
                    <AmbientLight Color="#ffcccccc"/>
                    <DirectionalLight Color="LightGray" Direction="-1,-1,-1" />
                  </Model3DGroup.Children>
                </Model3DGroup>
              </Model3DGroup.Children>
            </Model3DGroup>
          </ModelVisual3D.Content>
        </ModelVisual3D>
      </Viewport3D>
    </DockPanel>
  </DockPanel>
</UserControl>
